package com.wcg.util;

import com.wcg.javabean.User;

import com.wcg.mapper.UserMapper;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class UserMapperTest {
    SqlSession session;
    UserMapper mapper;
    @Before
    public void before() {
        SqlSessionFactory factory = MyBatisUtil.getSqlSessionFactory();
        session = factory.openSession(true);
        mapper = session.getMapper(UserMapper.class);

    }

    @After
    public void after() {
        session.close();
    }

    @Test
    public void selectAll(){
        for (User user : mapper.selectAll()) {
            System.out.println(user);
        }
    }

    @Test
    public void selectByUsernameAndPassword(){
        mapper.selectByUsernameAndPassword("a","a");
    }

    @Test
    public void selectByUid(){
        mapper.selectByUid(1);
    }
    @Test
    public void deleteByUid(){
        mapper.deleteByUid(18);
    }

    @Test
    public void insertUser(){
        User u=new User("a","a","a");
        mapper.insertUser(u);
    }

    @Test
    public void updatePasswordByUid(){
        mapper.updatePasswordByUid(4,"aa");
    }
    @Test
    public void selectAllUser(){
        for (User user : mapper.selectAllUser()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectAllUser1(){
        for (User user : mapper.selectAllUser1()) {
            System.out.println(user);
        }
    }

    @Test
    public void selectUser_Role(){
        for (User user : mapper.selectUser_Role()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectUser_Role1(){
        for (User user : mapper.selectUser_Role1()) {
            System.out.println(user);
        }
    }
    @Test
    public void selectByUser(){
        User u=new User();
        u.setUid(1);
        for (User user : mapper.selectByUser(u)) {
            System.out.println(user);
        }
    }

}